/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.suspend.b;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.text.TextUtils;
import android.util.Base64;
import com.qihoo.gamecenter.sdk.suspend.b.e.f;
import com.qihoo.gamecenter.sdk.suspend.b.e.h;
import java.io.IOException;
import java.net.URLEncoder;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.json.JSONObject;

public class c {
    private static String d = null;
    private static String e = null;
    private static String f = null;
    private static String g = null;
    public static int a = 0;
    public static int b = 0;
    private static int h = 0;
    public static String c = "";
    private static final char[] i = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };

    public static boolean a(String paramString) {
        if (TextUtils.isEmpty(paramString))
            return false;
        try {
            String str = "chmod 777 " + paramString;
            b.a("fileChmod777", "command = " + str);
            Runtime localRuntime = Runtime.getRuntime();
            localRuntime.exec(str);
        } catch (IOException localIOException) {
            b.a("fileChmod777", "chmod fail");
            localIOException.printStackTrace();
            return false;
        }
        return true;
    }

    public static int a(Context paramContext, String paramString) {
        int j = -1;
        try {
            PackageManager localPackageManager = paramContext.getPackageManager();
            PackageInfo localPackageInfo = localPackageManager.getPackageInfo(paramString, 0);
            j = localPackageInfo.versionCode;
            return j;
        } catch (Exception localException) {
            localException.printStackTrace();
        }
        return j;
    }

    public static String a(byte[] paramArrayOfByte) {
        StringBuilder localStringBuilder = new StringBuilder(paramArrayOfByte.length * 2);
        for (int j = 0; j < paramArrayOfByte.length; ++j) {
            localStringBuilder.append(i[((paramArrayOfByte[j] & 0xF0) >>> 4)]);
            localStringBuilder.append(i[(paramArrayOfByte[j] & 0xF)]);
        }
        return localStringBuilder.toString();
    }

    public static String a() {
        String str = b().substring(0, 8);
        return str;
    }

    public static String b() {
        try {
            SecureRandom localSecureRandom = SecureRandom.getInstance("SHA1PRNG");
            byte[] arrayOfByte = new byte[16];
            localSecureRandom.nextBytes(arrayOfByte);
            return a(arrayOfByte);
        } catch (NoSuchAlgorithmException localNoSuchAlgorithmException) {}
        return Long.toString(System.currentTimeMillis());
    }

    public static String a(List paramList) {
        ArrayList localArrayList = new ArrayList();
        Object localObject2 = paramList.iterator();
        while (((Iterator) localObject2).hasNext()) {
            localObject1 = (a) ((Iterator) localObject2).next();
            localArrayList.add(((a) localObject1).toString());
        }
        Collections.sort(localArrayList);
        Object localObject1 = new StringBuilder();
        Iterator localIterator = localArrayList.iterator();
        while (localIterator.hasNext()) {
            localObject2 = (String) localIterator.next();
            ((StringBuilder) localObject1).append((String) localObject2);
        }
        return ((String) (String) f.a(((StringBuilder) localObject1).toString()));
    }

    public static byte[] a(List paramList, String paramString) {
        StringBuilder localStringBuilder = new StringBuilder();
        for (int j = 0; j < paramList.size(); ++j) {
            a locala = (a) paramList.get(j);
            localStringBuilder.append(locala.a() + "=" + locala.b());
            if (j == paramList.size() - 1)
                continue;
            localStringBuilder.append("&");
        }
        return a(localStringBuilder.toString().getBytes(), paramString.getBytes());
    }

    public static byte[] a(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2) {
        Object localObject = null;
        IvParameterSpec localIvParameterSpec = null;
        SecretKeySpec localSecretKeySpec = null;
        Cipher localCipher = null;
        byte[] arrayOfByte = null;
        try {
            if ((paramArrayOfByte1 != null) && (paramArrayOfByte1.length > 0)) {
                localIvParameterSpec = new IvParameterSpec(paramArrayOfByte2);
                localSecretKeySpec = new SecretKeySpec(paramArrayOfByte2, "DES");
                localCipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
                localCipher.init(1, localSecretKeySpec, localIvParameterSpec);
                arrayOfByte = localCipher.doFinal(paramArrayOfByte1);
                localObject = arrayOfByte;
            }
        } catch (Exception localException) {}
        return localObject;
    }

    public static byte[] b(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2) {
        Object localObject = null;
        byte[] arrayOfByte1 = null;
        byte[] arrayOfByte2 = null;
        IvParameterSpec localIvParameterSpec = null;
        SecretKeySpec localSecretKeySpec = null;
        Cipher localCipher = null;
        try {
            if ((paramArrayOfByte1 != null) && (paramArrayOfByte1.length > 0)) {
                arrayOfByte1 = paramArrayOfByte1;
                localIvParameterSpec = new IvParameterSpec(paramArrayOfByte2);
                localSecretKeySpec = new SecretKeySpec(paramArrayOfByte2, "DES");
                localCipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
                localCipher.init(2, localSecretKeySpec, localIvParameterSpec);
                arrayOfByte2 = localCipher.doFinal(arrayOfByte1);
                localObject = arrayOfByte2;
            }
        } catch (Exception localException) {}
        return localObject;
    }

    public static String a(String paramString1, List paramList1, List paramList2, List paramList3, String paramString2) {
        byte[] arrayOfByte1 = h.a(paramString2.getBytes());
        String str1 = new String(Base64.encode(arrayOfByte1, 0));
        if (paramList1 == null)
            paramList1 = new ArrayList();
        paramList1.add(new a("rkey", str1));
        String str2 = null;
        if ((paramList2 != null) && (!(paramList2.isEmpty()))) {
            localArrayList = new ArrayList();
            localArrayList.addAll(paramList1);
            localArrayList.addAll(paramList2);
            str2 = a(localArrayList);
        }
        else {
            str2 = a(paramList1);
        }
        ArrayList localArrayList = new ArrayList();
        localArrayList.add(new a("sign", str2));
        if ((paramList3 != null) && (!(paramList3.isEmpty())))
            localArrayList.addAll(paramList3);
        byte[] arrayOfByte2 = a(localArrayList, paramString2);
        String str3 = new String(Base64.encode(arrayOfByte2, 0));
        paramList1.add(new a("signid", str3));
        StringBuilder localStringBuilder = new StringBuilder();
        localStringBuilder.append(paramString1);
        int j = 0;
        int k = paramList1.size();
        while (j < k) {
            if (!("?".equals(Character.valueOf(localStringBuilder.charAt(localStringBuilder.length() - 1)))))
                localStringBuilder.append("&");
            if (TextUtils.isEmpty(((a) paramList1.get(j)).b()))
                localStringBuilder.append(((a) paramList1.get(j)).a() + "=" + ((a) paramList1.get(j)).b());
            else
                localStringBuilder.append(((a) paramList1.get(j)).a() + "="
                        + URLEncoder.encode(((a) paramList1.get(j)).b()));
            ++j;
        }
        return localStringBuilder.toString();
    }

    public static List b(String paramString1, List paramList1, List paramList2, List paramList3, String paramString2) {
        ArrayList localArrayList1 = new ArrayList();
        byte[] arrayOfByte1 = h.a(paramString2.getBytes());
        String str1 = new String(Base64.encode(arrayOfByte1, 0));
        if (paramList1 == null)
            paramList1 = new ArrayList();
        paramList1.add(new a("rkey", str1));
        String str2 = null;
        if ((paramList2 != null) && (!(paramList2.isEmpty()))) {
            localArrayList2 = new ArrayList();
            localArrayList2.addAll(paramList1);
            localArrayList2.addAll(paramList2);
            str2 = a(localArrayList2);
        }
        else {
            str2 = a(paramList1);
        }
        ArrayList localArrayList2 = new ArrayList();
        localArrayList2.add(new a("sign", str2));
        if ((paramList3 != null) && (!(paramList3.isEmpty())))
            localArrayList2.addAll(paramList3);
        byte[] arrayOfByte2 = a(localArrayList2, paramString2);
        String str3 = new String(Base64.encode(arrayOfByte2, 0));
        StringBuilder localStringBuilder = new StringBuilder();
        localStringBuilder.append(paramString1);
        int j = 0;
        int k = paramList1.size();
        while (j < k) {
            if (!("?".equals(Character.valueOf(localStringBuilder.charAt(localStringBuilder.length() - 1)))))
                localStringBuilder.append("&");
            if (TextUtils.isEmpty(((a) paramList1.get(j)).b()))
                localStringBuilder.append(((a) paramList1.get(j)).a() + "=");
            else
                localStringBuilder.append(((a) paramList1.get(j)).a() + "="
                        + URLEncoder.encode(((a) paramList1.get(j)).b()));
            ++j;
        }
        localArrayList1.add(new a("url", localStringBuilder.toString()));
        localArrayList1.add(new a("signid", str3));
        return localArrayList1;
    }

    public static String a(String paramString1, String paramString2) {
        if ((paramString1 == null) || (paramString2 == null))
            return null;
        String str = paramString1;
        try {
            byte[] arrayOfByte = Base64.decode(paramString1, 0);
            str = new String(b(arrayOfByte, paramString2.getBytes()), "UTF-8");
        } catch (Exception localException1) {
            try {
                JSONObject localJSONObject = new JSONObject(paramString1);
                str = localJSONObject.toString();
            } catch (Exception localException2) {}
        }
        return str;
    }

    public static String c() {
        return UUID.randomUUID().toString();
    }

    public static class a {
        private String a;
        private String b;

        public String a() {
            return this.a;
        }

        public String b() {
            return this.b;
        }

        public a(String paramString1, String paramString2) {
            this.a = paramString1;
            this.b = paramString2;
        }

        public String toString() {
            return this.a + this.b;
        }
    }
}